package com.njit.WeStudy.dao;

import com.njit.WeStudy.dataobject.User;
import java.util.List;

import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;

public interface UserMapper {
    @Delete({
        "delete from user",
        "where user_id = #{userId,jdbcType=INTEGER}"
    })
    int deleteByPrimaryKey(Integer userId);

    @Insert({
        "insert into user (user_name, user_type,",
        "email, phone,",
        "password,head_image) ",
        "values (#{userName,jdbcType=VARCHAR},#{userType,jdbcType=VARCHAR}, ",
        " #{email,jdbcType=VARCHAR},#{phone,jdbcType=VARCHAR},  ",
        "#{password,jdbcType=VARCHAR},#{headImage,jdbcType=VARCHAR})"
    })
    int insert(User record);

    @Select({
        "select",
        "user_id, user_name, user_type, email, phone, password,head_image",
        "from user",
        "where user_id = #{userId,jdbcType=INTEGER}"
    })
    @Results(id = "resultMap",value = {
        @Result(column="user_id", property="userId", jdbcType=JdbcType.INTEGER, id=true),
        @Result(column="user_name", property="userName", jdbcType=JdbcType.VARCHAR),
        @Result(column="user_type", property="userType", jdbcType=JdbcType.VARCHAR),
        @Result(column="email", property="email", jdbcType=JdbcType.VARCHAR),
        @Result(column="phone", property="phone", jdbcType=JdbcType.VARCHAR),
        @Result(column="password", property="password", jdbcType=JdbcType.VARCHAR),
        @Result(column="head_image", property="headImage", jdbcType=JdbcType.VARCHAR)
    })
    User selectByPrimaryKey(Integer userId);

    @SelectProvider(type = QueryBuilder.class,method = "query")
    @ResultMap("resultMap")
    List<User> selectBy(@Param(value = "info") String info,@Param(value = "str") String str);

    @Select({
        "select",
        "user_id, user_name, user_type, email,phone, password,head_image",
        "from user"
    })
    @ResultMap("resultMap")
    List<User> selectAll();

    @Update({
        "update user",
        "set user_name = #{userName,jdbcType=VARCHAR},",
          "user_type = #{userType,jdbcType=VARCHAR},",
          "email = #{email,jdbcType=VARCHAR},",
          "phone = #{phone,jdbcType=VARCHAR},",
          "password = #{password,jdbcType=VARCHAR}",
            "head_image = #{headImage,jdbcType=VARCHAR}",
        "where user_id = #{userId,jdbcType=INTEGER}"
    })
    int updateByPrimaryKey(User record);

    @UpdateProvider(type = UpdateBuilder.class,method = "update")
    int updateOneById(@Param(value = "info") String info,@Param(value = "str") String str,@Param(value = "id") int id);
}